import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * service - 单位定义
 * @date: 2018-7-6


 */
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { getCurrentOrganizationId, isTenantRoleLevel, parseParameters } from 'utils/utils';
/**
 * 请求API前缀
 * @type {string}
 */

var prefix = "".concat(CPAAS_PLATFORM, "/v1").concat(isTenantRoleLevel() ? "/".concat(getCurrentOrganizationId()) : '');
/**
 * 查询平台级计量单位
 * @async
 * @function searchUomData
 * @param {object} params - 查询条件
 * @param {?string} params.uomName - 计量单位名称
 * @param {?string} params.uomCode - 计量单位编码
 * @param {!Object} params.page- 分页参数
 * @returns {object} fetch Promise
 */

export function searchUomData(_x) {
  return _searchUomData.apply(this, arguments);
}
/**
 * 保存平台级计量单位
 * @async
 * @function saveUomData
 * @param {Object} params - 请求参数
 * @param {Object[]} params.saveData - 待保存的数据列表
 * @param {?string} params.saveData[].uomId - 计量单位ID
 * @param {!string} params.saveData[].uomCode - 计量单位编码
 * @param {!string} params.saveData[].uomName - 计量单位名称
 * @param {?string} params.saveData[].uomTypeCode - 计量单位类型编码
 * @param {number} [params.saveData[].tenantId = 0] - 租户Id
 * @param {number} [params.saveData[].enabledFlag = 1] - 启用标记
 * @returns {object} fetch Promise
 */

function _searchUomData() {
  _searchUomData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            param = parseParameters(params);
            return _context.abrupt("return", request("".concat(prefix, "/uom"), {
              method: 'GET',
              query: param
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _searchUomData.apply(this, arguments);
}

export function saveUomData(_x2) {
  return _saveUomData.apply(this, arguments);
}

function _saveUomData() {
  _saveUomData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(prefix, "/uom"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _saveUomData.apply(this, arguments);
}